﻿using SMS.cntr;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using SMS.util;
using System.Resources;

namespace SMS.view
{
    public partial class ReportAllSemestersForm : Form
    {
        public ReportAllSemestersForm()
        {
            InitializeComponent();
        }

        private void bindSemester()
        {
            cbSemester.DataSource = GradeCntr.Instance.listSemester();
            cbSemester.DisplayMember = "sem_name";
            cbSemester.ValueMember = "sem_id";
            cbSemester.Text = "Chọn Học Kỳ";
            
        }

        private void frmSemesterReport_Load(object sender, EventArgs e)
        {
            bindSemester();
            changeLang(I18nUtil.vnLang);
        }

        private void bindGridViewRate()
        {
            gridViewSemesterReport.Rows.Clear();
            int semID = int.Parse(cbSemester.SelectedValue.ToString());
            DataTable table = GradeCntr.Instance.listClassRateBySemester(semID);
            for (int i = 0; i < table.Rows.Count; i++)
            {
                gridViewSemesterReport.Rows.Add(i + 1, table.Rows[i]["cla_name"].ToString(), table.Rows[i]["cla_counted"].ToString(), table.Rows[i]["cla_passed"].ToString(), table.Rows[i]["rate"].ToString());
                gridViewSemesterReport.Rows[gridViewSemesterReport.RowCount - 1].Tag = table.Rows[i];
            }
            gridViewSemesterReport.ClearSelection();
        }

        private void cbSemester_SelectedIndexChanged(object sender, EventArgs e)
        {
            try
            {
                bindGridViewRate();
            }
            catch (Exception ex) { }
        }

        public void changeLang(string lang)
        {
            I18nUtil.init(lang, new ResourceManager(I18nUtil.resourcePath, typeof(ReportAllCoursesForm).Assembly));

            this.Text = I18nUtil.getString("reportAllSemesters");
            lblSemester.Text = I18nUtil.getString("lblSemester");
            gridViewSemesterReport.Columns[0].HeaderText = I18nUtil.getString("no");
            gridViewSemesterReport.Columns[1].HeaderText = I18nUtil.getString("lblClass");
            gridViewSemesterReport.Columns[2].HeaderText = I18nUtil.getString("lblClassCapacity");
            gridViewSemesterReport.Columns[3].HeaderText = I18nUtil.getString("numberOfPassStudent");
            gridViewSemesterReport.Columns[4].HeaderText = I18nUtil.getString("rateOfPass");
        }

    }
}
